var $parentNode = window.parent.document;

function $childNode(name) {
    return window.frames[name]
}

// tooltips
$('.tooltip-demo').tooltip({
    selector: "[data-toggle=tooltip]",
    container: "body"
});

// 使用animation.css修改Bootstrap Modal
$('.modal').appendTo("body");

$("[data-toggle=popover]").popover();

//折叠ibox
$('.collapse-link').click(function () {
    var ibox = $(this).closest('div.ibox');
    var button = $(this).find('i');
    var content = ibox.find('div.ibox-content');
    content.slideToggle(200);
    button.toggleClass('fa-chevron-up').toggleClass('fa-chevron-down');
    ibox.toggleClass('').toggleClass('border-bottom');
    setTimeout(function () {
        ibox.resize();
        ibox.find('[id^=map-]').resize();
    }, 50);
});

//关闭ibox
$('.close-link').click(function () {
    var content = $(this).closest('div.ibox');
    content.remove();
});

//判断当前页面是否在iframe中
if (top == this) {
    var gohome = '<div class="gohome"><a class="animated bounceInUp" href="index.html?v=4.0" title="返回首页"><i class="fa fa-home"></i></a></div>';
    $('body').append(gohome);
}

//animation.css
function animationHover(element, animation) {
    element = $(element);
    element.hover(
        function () {
            element.addClass('animated ' + animation);
        },
        function () {
            //动画完成之前移除class
            window.setTimeout(function () {
                element.removeClass('animated ' + animation);
            }, 2000);
        });
}

//拖动面板
function WinMove() {
    var element = "[class*=col]";
    var handle = ".ibox-title";
    var connect = "[class*=col]";
    $(element).sortable({
            handle: handle,
            connectWith: connect,
            tolerance: 'pointer',
            forcePlaceholderSize: true,
            opacity: 0.8,
        })
        .disableSelection();
}
// 日期选择器
$('#RegistrationTime .form-control').datepicker({
            language: "zh-CN"
        });

$('#IncubationTime .form-control').datepicker({
            language: "zh-CN"
        });


//获取当前iframe
function getFrameInParent(){
    var len =  parent.document.getElementsByTagName("iframe").length;
    for(var i = 0; i < len; i++){
        if(parent.document.getElementsByTagName("iframe")[i].contentWindow.document === document){
            return parent.document.getElementsByTagName("iframe")[i];
        }
    }
}


//iframe 内容发生变化时自动重新加载
function changeFrameHeight(myFrame,url){
    myFrame.src= url;
}


function submitAlert(){
    swal({
            closeOnClickOutside: false,
            closeOnEsc: false,
            title: "提交成功",
            text: "已提交",
            icon: "success"
        }).then(function (isConfirm) {
        if (isConfirm === true) {
            // 刷新当前页面
            var urlPage = location.href; //把当前页面的地址赋给变量 url
            var newUrl = urlPage.replace("edit.htm","editoc.htm");
            changeFrameHeight(getFrameInParent(),newUrl);
        }
    })
}


$("#BasicInformation").validate({
    // focusCleanup:true,
    submitHandler:function(form) {
        $(form).ajaxSubmit({
            type: 'post',
            url: '/reportform/',
            success: function(data){
                if (data.response == 1) {
                    submitAlert();
                }
            }
        })
    }
});


function submitModifySuccess(){
    swal({
            title: "修改成功",
            text: "已修改",
            icon: "success",
            closeOnClickOutside: false,
            closeOnEsc: false,
        }).then(function (isConfirm) {

        if (isConfirm === true) {
            parent.layer.closeAll();
            let $tableReview = parent.$('#tableReview');
            parent.tableReviewData();
        }
    })
}


function submitModifyError(){
    swal({
            title: "修改失败",
            text: "修改失败",
            icon: "error"
        }).then(function (isConfirm) {
        if (isConfirm === true) {
            console.log("hello motpo")
        }
    })
};

$("#ModifyInformation").validate({
    // focusCleanup:true,
    submitHandler:function(form) {
        $(form).ajaxSubmit({
            type: 'post',
            url: '/modifyform/',
            data: {
                'fId': sessionStorage.getItem('fId'),
            },
            success: function(data){
                if (data.response == 1) {
                    submitModifySuccess();
                }
                if (data.response == 0) {
                    submitModifyError();
                }
            }
        })
    }
});








